﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GadgetBase
{
    public abstract class SystemButton : UserControl
    {
        private ImageBrush smallBrush;
        private ImageBrush largeBrush;
        private SizeMode sizeMode = SizeMode.Large;

        public SystemButton()
        {
            base.SnapsToDevicePixels = true;

            this.smallBrush = new ImageBrush(GlobalMethods.GetBitmapImage(GetSmallBackgroundImagePath()));
            this.largeBrush = new ImageBrush(GlobalMethods.GetBitmapImage(GetLargeBackgroundImagePath()));

            SetBackground();
        }

        public SizeMode SizeMode
        {
            get
            {
                return this.sizeMode;
            }
            set
            {
                this.sizeMode = value;
                OnSizeModeChanged();
            }
        }

        protected abstract string GetSmallBackgroundImagePath();
        protected abstract string GetLargeBackgroundImagePath();

        public Size DefaultSize
        {
            get
            {
                switch (this.sizeMode)
                {
                    default:
                    case SizeMode.Small:
                        {
                            return new Size(smallBrush.ImageSource.Width, smallBrush.ImageSource.Height);
                        }
                    case SizeMode.Large:
                        {
                            return new Size(largeBrush.ImageSource.Width, largeBrush.ImageSource.Height);
                        }
                }
            }
        }

        public void ResetSize()
        {
            this.Width = this.DefaultSize.Width;
            this.Height = this.DefaultSize.Height;
        }

        protected virtual void OnSizeModeChanged()
        {
            SetBackground();
        }

        private void SetBackground()
        {
            base.Background = (this.sizeMode != SizeMode.Large ? smallBrush : largeBrush);
            this.ResetSize();           
        }        
    }
}
